package com.itheima.controller;

import com.itheima.dao.RoleDao;
import com.itheima.domain.Role;
import com.itheima.service.RoleSeveice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;




import java.util.List;

@RequestMapping("/role")
@Controller
public class RoleController {

    @Autowired
    private RoleSeveice roleSeveice;

//    public void setRoleSeveice(RoleSeveice roleSeveice) {
//        this.roleSeveice = roleSeveice;
//    }
    @RequestMapping("/save")
    public String save(Role role){
        roleSeveice.save(role);
        return "redirect:/role/list";
    }



    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView modelAndView = new ModelAndView();
        List<Role> rolelist = roleSeveice.list();
        //添加模型
        modelAndView.addObject("rolelist",rolelist);
        //添加视图
        modelAndView.setViewName("role-list");
        return modelAndView;
    }

//    public static void main(String[] args){
//        System.out.println("Role");
//    }

}
